package com.hezhi.project.module.leave.service;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hezhi.common.utils.StringUtils;
import com.hezhi.project.module.leave.mapper.LeaveMapper;
import com.hezhi.project.module.leave.domain.Leave;
import com.hezhi.project.module.leave.service.ILeaveService;
import com.hezhi.common.support.Convert;

/**
 * 请假 服务层实现
 * 
 * @author hezhi
 * @date 2018-08-19
 */
@Service
public class LeaveServiceImpl implements ILeaveService 
{
	@Autowired
	private LeaveMapper leaveMapper;

	/**
     * 查询请假信息
     * 
     * @param leaveId 请假ID
     * @return 请假信息
     */
    @Override
	public Leave selectLeaveById(Integer leaveId)
	{
	    return leaveMapper.selectLeaveById(leaveId);
	}
	
	/**
     * 查询请假列表
     * 
     * @param leave 请假信息
     * @return 请假集合
     */
	@Override
	public List<Leave> selectLeaveList(Leave leave)
	{
	    return leaveMapper.selectLeaveList(leave);
	}
	
    /**
     * 新增请假
     * 
     * @param leave 请假信息
     * @return 结果
     */
	@Override
	public int insertLeave(Leave leave)
	{
	    return leaveMapper.insertLeave(leave);
	}
	
	/**
     * 修改请假
     * 
     * @param leave 请假信息
     * @return 结果
     */
	@Override
	public int updateLeave(Leave leave)
	{
	    return leaveMapper.updateLeave(leave);
	}
	
	/**
     * 保存请假
     * 
     * @param leave 请假信息
     * @return 结果
     */
	@Override
	public int saveLeave(Leave leave)
	{
	    Integer leaveId = leave.getLeaveId();
		int rows = 0;
		if (StringUtils.isNotNull(leaveId))
        {
		    rows = leaveMapper.updateLeave(leave);
		}
		else
        {
		    rows = leaveMapper.insertLeave(leave);
		}
		return rows;
	}
	
	/**
     * 删除请假对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteLeaveByIds(String ids)
	{
		return leaveMapper.deleteLeaveByIds(Convert.toIntArray(ids));
	}
	
}
